package jdbc10_18;

import java.io.File;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class StudentDal {
    public int add(Student stu){
        return 0;
    }
    public int update(Student stu){
        return 0;
    }
    public Student get(long stuno){
        return null;
    }
    public List<Student> findALL(){
        ArrayList<Student> ob = new ArrayList<>();
        String sql="select * from s_student";
        PreparedStatement pas=null;
        ResultSet rset=null;
        try {
             pas = DBUtil.getConnection().prepareStatement(sql);
             rset = pas.executeQuery();
            while (rset.next()){
                Student student = new Student();
                student.setStuno(rset.getLong("stuno"));
                student.setSname(rset.getString("sname"));
                student.setSex(rset.getString("sex"));
                student.setTelephone(rset.getString("telephone"));
                student.setQq(rset.getString("qq"));
                student.setWechat(rset.getString("wechat"));
                student.setGradeid(rset.getLong("gradeid"));
                student.setEnterdate(rset.getDate("enterdate"));
                student.setFromcity(rset.getString("fromcity"));
                student.setBirthday(rset.getDate("birthday"));
                student.setAddress(rset.getString("address"));
                student.setPass(rset.getString("pass"));
                student.setIdcardpic(rset.getString("idcardpic"));
                ob.add(student);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rset);
            DBUtil.close(pas);
        }
        return ob;
    }
}
